home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / memory / demm.zip / STDFUNC.ASM < prev    next >
Assembly Source File  |  1986-10-08  |  17KB  |  272 lines

  1. ;*--------------------------------------------------------------------*
  2. ;* STDFUNC -- This is a standard set of Assembler Subroutines that    *
  3. ;*            are contained in the STDFUNC.LIB standard assembler     *
  4. ;*            linkage library.                                        *
  5. ;*                                                                    *
  6. ;* Author: J.C. Weilandt II  Date: 10-07-86  Last Update: 10-08-86    *
  7. ;*                                                                    *
  8. ;* Functions Contained:                                               *
  9. ;*     stdout   -- output a single character to the standard out dev  *
  10. ;*     stdcrlf  -- output a carriage return/line feed sequence stdout *
  11. ;*     stdin    -- input a single character with echo from stdin      *
  12. ;*     stdinne  -- input a single character w/o echo from stdin       *
  13. ;*     dec8out  -- converts 8-bit binary to decimal and prints        *
  14. ;*     dec16out -- converts 16-bit binary to decimal and prints       *
  15. ;*     return   -- return to MS-DOS                                   *
  16. ;*     prtstr   -- prints a string terminated by $                    *
  17. ;*     clrscr   -- clear the video display screen                     *
  18. ;*     hex8out  -- convert 8-bit binary to display hex and print      *
  19. ;*     hex16out -- convert 16-bit binary to display hex and print     *
  20. ;*                                                                    *
  21. ;*--------------------------------------------------------------------*
  22. ;
  23. codes    segment                  ;dummy segment for assembler
  24.          public stdout            ;so we can find it later
  25.          public stdcrlf           ;so we can find it later
  26.          public stdin             ;so we can find it later
  27.          public stdinne           ;so we can find it later
  28.          public dec8out           ;so we can find it later
  29.          public dec16out          ;so we can find it later
  30.          public return            ;so we can find it later
  31.          public prtstr            ;so we can find it later
  32.          public clrscr            ;so we can find it later
  33.          public hex8out           ;so we can find it later
  34.          public hex16out          ;so we can find it later
  35.          assume cs:codes          ;dummy code segment fixup
  36. ;
  37. ;*--------------------------------------------------------------------*
  38. ;* stdout   -- output a single character to standard output device    *
  39. ;*                                                                    *
  40. ;* call_seq    mov   al,_char_    ;move character to al register      *
  41. ;*             call  stdout       ;write character on stdout          *
  42. ;*--------------------------------------------------------------------*
  43. stdout   proc  far                 ;procedure header
  44.          push  dx                  ;save the dx register pair
  45.          mov   dl,al               ;load character to print
  46.          mov   ah,2                ;load DOS function number
  47.          int   21h                 ;issue DOS function call
  48.          pop   dx                  ;restore dx register pair
  49.          ret                       ;return to caller
  50. stdout   endp                      ;procedure trailer
  51. ;*--------------------------------------------------------------------*
  52. ;* stdcrlf  -- output a carriage return/line feed sequence to stdout  *
  53. ;*                                                                    *
  54. ;* call_seq    call  stdcrlf      ;write out CR/LF combination        *
  55. ;*--------------------------------------------------------------------*
  56. stdcrlf  proc  far                 ;procedure header
  57.          push  ax                  ;save the ax register pair
  58.          mov   al,0dh              ;load character to print
  59.          call  stdout              ;write out the carriage return
  60.          mov   al,0ah              ;load character to print
  61.          call  stdout              ;write out the line feed
  62.          pop   ax                  ;restore ax register pair
  63.          ret                       ;return to caller
  64. stdcrlf  endp                      ;procedure trailer
  65. ;*--------------------------------------------------------------------*
  66. ;* stdin    -- input a single character from standard input device    *
  67. ;*                                                                    *
  68. ;* call_seq    call  stdin        ;read character from console        *
  69. ;*--------------------------------------------------------------------*
  70. stdin    proc  far                 ;procedure header
  71.          mov   ah,1                ;load DOS function number
  72.          int   21h                 ;issue DOS function call
  73.          ret                       ;return to caller
  74. stdin    endp                      ;procedure trailer
  75. ;*--------------------------------------------------------------------*
  76. ;* stdinne  -- input a single character from stdin with no echo       *
  77. ;*                                                                    *
  78. ;* call_seq    call  stdinne      ;read character from cons w/o echo  *
  79. ;*--------------------------------------------------------------------*
  80. stdinne  proc  far                 ;procedure header
  81.          mov   ah,8                ;load DOS function number
  82.          int   21h                 ;issue DOS function call
  83.          ret                       ;return to caller
  84. stdinne  endp                      ;procedure trailer
  85. ;*--------------------------------------------------------------------*
  86. ;* dec8out  -- convert 8-bit binary to decimal and print to stdout    *
  87. ;*                                                                    *
  88. ;* call_seq    mov   dl,_bin_     ;move binary number to dl register  *
  89. ;*             call  dec8out      ;convert to decimal and print out   *
  90. ;*--------------------------------------------------------------------*
  91. dec8out  proc  far                 ;procedure header
  92.          push  ds                  ;save data segment register
  93.          push  di                  ;save di register pair
  94.          push  dx                  ;save work register pair
  95.          push  cx                  ;save count register pair
  96.          push  ax                  ;save accumulator register pair
  97.          mov   ax,seg tbuff        ;get segment address of buffer
  98.          mov   ds,ax               ;put into data segment register
  99.          mov   cx,0                ;initialize counter
  100.          mov   di,offset tbuff     ;point to buffer area
  101. dec8out1:
  102.          push  cx                  ;save counter register pair
  103.          mov   al,dl               ;AX now has the numerator
  104.          mov   ah,0                ;clear upper half
  105.          mov   cl,10               ;divisor of 10
  106.          div   cl                  ;do the division
  107.          mov   dl,al               ;get the quotient
  108.          mov   al,ah               ;get the remainder
  109.          add   al,30h              ;make numeric display
  110.          mov   [di],al             ;put number into buffer
  111.          inc   di                  ;point to the next byte
  112.          pop   cx                  ;restore counter
  113.          inc   cx                  ;count the digit
  114.          cmp   dl,0                ;q.are we all done ??
  115.          jnz   dec8out1            ;nope, go do more
  116. dec8out2:
  117.          dec   di                  ;back up through buffer
  118.          mov   al,[di]             ;get byte from buffer
  119.          call  stdout              ;write out the number
  120.          loop  dec8out2            ;loop until cx=0
  121.          pop   ax                  ;restore accumulator pair
  122.          pop   cx                  ;restore counter pair
  123.          pop   dx                  ;restore work register pair
  124.          pop   di                  ;restore index pair
  125.          pop   ds                  ;restore data segment pair
  126.          ret                       ;return to caller
  127. tbuff    dw   32(?)                ;buffer storage
  128. dec8out  endp                      ;procedure trailer
  129. ;*--------------------------------------------------------------------*
  130. ;* dec16out -- convert 16-bit binary to decimal and print to stdout   *
  131. ;*